package com.leyou.upload.web;

import com.leyou.upload.service.UploadService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * description: 上传文件接口
 * @author 朱正磊
 * @date 2021-03-29 00:58:59
 */
@RestController
@RequestMapping("upload")
public class UploadController {

    @Resource
    private UploadService uploadService;

    /**
     * description: 上传图片
     * @author 朱正磊
     * @date 2021-03-29 01:05:56
     * @param file 图片对象
     * @return 返回图片存储的地址
     */
    @PostMapping("image")
    public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file) {
        return ResponseEntity.ok(uploadService.uploadImage(file));
    }

}
